package com.ssm.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.ssm.oss.adapter.AliStorageAdapter;
import com.ssm.oss.adapter.MinioStorageAdapter;
import com.ssm.oss.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${storage.service.type}")
    private String storageType;
    @Bean
    @RefreshScope //当文件更新后，带有此注解的Bean能够自动重新初始化
    public StorageAdapter storageAdapter() {
        if("minio".equals(storageType)) {
            return new MinioStorageAdapter();
        } else if("aliyun".equals(storageType)) {
            return new AliStorageAdapter();
        } else {
            throw new IllegalArgumentException("未找到对应的文件存储处理器");
        }
    }
}
